package net.starwifi.duobao.entity;

import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.commons.lang.builder.CompareToBuilder;

import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import javax.validation.constraints.Min;

/**
 * Entity - 基类(有排序需求的数据).
 *
 * @author <a href="http://ruoo.whosenet.com">ruoo.whosenet.com</>
 * @version 1.0
 */

@MappedSuperclass
public class OrderEntity extends BaseEntity implements Comparable<OrderEntity>  {

    private static final long serialVersionUID = 5995013015967525827L;

    /** "排序"属性名称 */
    public static final String ORDER_PROPERTY_NAME = "order";

    /** 排序 */
    private Integer order;

    /**
     * 获取排序
     *
     * @return 排序
     */
    @JsonProperty
    @Min(0)
    @Column(name = "orders_id")
    public Integer getOrder() {
        return order;
    }

    /**
     * 设置排序
     *
     * @param order
     *            排序
     */
    public void setOrder(Integer order) {
        this.order = order;
    }

    /**
     * 实现compareTo方法
     *
     * @param orderEntity
     *            排序对象
     * @return 比较结果
     */
    public int compareTo(OrderEntity orderEntity) {
        return new CompareToBuilder().append(getOrder(), orderEntity.getOrder()).append(getId(), orderEntity.getId()).toComparison();
    }
}
